package com.vinyl.components 
{	
	import flash.events.*;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	//tweener
	import com.greensock.*;
	import com.greensock.easing.*;
	
	import com.vinyl.components.SimpleFlvPlayer;
	
	public class SimpleFlvPlayerUi extends MovieClip
	{	
		private var _owner:SimpleFlvPlayer;
		public var autoSize:Boolean = false;
		
		/**
		 * constructor
		 * @param SimpleFlvPlayerUi ( void )
		 */
		public function SimpleFlvPlayerUi( $owner:SimpleFlvPlayer )
		{
			super();
			_owner = $owner;
			alpha = 0;
			init();
		}
		
		private function init()
		{
			addEventListener( Event.ADDED_TO_STAGE, function(e){
				stage.addEventListener( Event.RESIZE, resizeHandler );
				stage.dispatchEvent( new Event( Event.RESIZE ) );
				removeEventListener( Event.ADDED_TO_STAGE,  arguments.callee );
			} );
			
			addEventListener( Event.REMOVED_FROM_STAGE, function(e)
			{ 
				//trace( "SimpleFlvPlayerUi removed EventListener" );
				stage.removeEventListener( Event.RESIZE, resizeHandler );
				removeEventListener( Event.REMOVED_FROM_STAGE,  arguments.callee );
			} );
			
			addEventListener( MouseEvent.ROLL_OVER, function(e)
			{
				TweenMax.to( e.currentTarget , .35, { alpha: 1, ease: Quad.easeInOut } );
				
			});
			
			addEventListener( MouseEvent.ROLL_OUT, function(e)
			{
				TweenMax.to( e.currentTarget , .35, { alpha: 0, ease: Quad.easeInOut } );
			});
		}
		
		private function resizeHandler( event:Event ):void  
		{
			trace( "SimpleFlvPlayerUi resize" );
			if( stage.displayState == "fullScreen" || autoSize  )
			{
				bar.width = stage.stageWidth - 50;
				pg_bar.width = stage.stageWidth - 50 -101;
				pgDownload_bar.width = stage.stageWidth - 50 -101;
				seekBar.width = stage.stageWidth - 50 - 150;
				
				totalTime.x =  stage.stageWidth - totalTime.width - 10 - 50 -101;
				
				soundSp.x =  stage.stageWidth - 50 -101;
				fullScrBtn.x =  stage.stageWidth - 50 - 51;
				
				playBtn.x = stage.stageWidth / 2 - playBtn.width / 2;
				playBtn.y = -stage.stageHeight / 2 - playBtn.height / 2;
				
				y = stage.stageHeight - 50 - 10;
				
				//프로젝트에 맞게 커스터마이징 필요
				if( stage.stageWidth / stage.stageHeight > 1.777 )
				{
					_owner.simpleFlv.width = stage.stageWidth;
					_owner.simpleFlv.scaleY = _owner.simpleFlv.scaleX;
				}
				else
				{
					_owner.simpleFlv.height = stage.stageHeight;
					_owner.simpleFlv.scaleX = _owner.simpleFlv.scaleY;
				}
				
				_owner.bg.width = stage.stageWidth;
				_owner.bg.height = stage.stageHeight;
			}
			else
			{
				x = 20;
				y = 310;
				
				bar.width = 600;
				pg_bar.width =450;
				pgDownload_bar.width = 450;
				seekBar.width = 450;
				
				totalTime.x =  420;
				
				soundSp.x = 499;
				fullScrBtn.x = 550;
				
				playBtn.x = 97;
				playBtn.y = -250;
				
				_owner.x = _owner.y = 0;
				_owner.simpleFlv.scaleX = _owner.simpleFlv.scaleY = 1;
				_owner.bg.scaleX = 1;
				_owner.bg.scaleY = 1;
			}
		}
	}
}





